
/*
 * @Author       : 吴豪
 * @Date         : 2021-12-4 15:56:22
 * @FilePath     : \book-manage-front\src\services\books.ts
 * @Description  : 图书管理页面接口文件
 */

import { request } from 'umi';
import type { addBookType, bookInfoType, BookList, BookListType, damageBookType } from '../dataType'

/**
 * 1.获取图书列表
 * @param params 
 */
export async function getBookList(params: BookListType) {
    return request<{ rowsNum: number; bookNum: number; list: BookList[] }>('/bookManage/getBookList', { params });
}

/**
 * 2.获取图书类型列表
 * @param params 
 */
export async function getBookTypeList() {
    return request<{ aid: number; name: number; }[]>('/bookManage/getBookTypeList', {});
}


/**
 * 3.获取图书信息
 * @param params 
 * @returns 
 */
export async function getBookInfo(params: { aid: number }) {
    return request<{
        name: string;
        typeAid: number;
        isbn: string;
        quantity: number;
        remarks?: string;
    }>('/bookManage/getBookInfo', { params, method: 'GET' })
}

/**
 * 4.检查图书ISBN号是否存在
 * @param params 
 * @returns 
 */
export async function checkISBNExist(params: { aid: number; isbn: string }) {
    return request<{ isExist: boolean; bookInfo?: bookInfoType }>('/bookManage/checkISBNExist', { params })
}


/**
 * 5.添加图书
 * @returns 
 */
export async function saveBookInfo(params: addBookType) {
    return request('/bookManage/saveBookInfo', {
        data: params,
        method: 'POST'
    })
}

/**
 * 6.确认损坏
 * @returns 
 */
export async function damageConfirm(params: damageBookType) {
    return request('/bookManage/damageConfirm', {
        data: params,
        method: 'POST'
    })
}

/**
 * 7.删除图书
 * @param params 
 */
export async function deleteBook(params: { aid: number }) {
    return request('/bookManage/deleteBook', {
        data: params,
        method: 'POST'
    });
}